package com.cwd.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.cwd.common.AjaxResult;
import com.cwd.entity.User;
import com.cwd.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Administrator on 2017/4/7.
 */
@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private IUserService userService;
    @GetMapping(value = "list")
    @ResponseBody
    public Object list(){
        List<User> users = userService.selectList(null);
        return new AjaxResult(true,users,users.size());
    }

    @GetMapping(value = "add")
    @ResponseBody
    public Object add(@RequestParam String name,@RequestParam String password){
        User user = new User();
        user.setName(name);
        user.setPassword(password);
        user.insert();
        return new AjaxResult(user,true);
    }
}
